package handlers

import (
	"github.com/gin-gonic/gin"
	"novel-hub/models"
	"novel-hub/pkg"
)

func Login(c *gin.Context) {
	username := c.PostForm("username")
	password := c.PostForm("password")
	user := models.User{
		Username: username,
		Password: pkg.Md5(password),
	}
	err := models.DB.Create(&user).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "登录失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "登录成功",
	})
	return
}
func List(c *gin.Context) {
	var post []models.Post
	err := models.DB.Find(&post).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "查询失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查询成功",
	})
	return
}
func Detail(c *gin.Context) {
	id := c.Query("id")
	var post models.User
	models.DB.First(&post, id)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "详情查询成功",
	})
	return
}
